package com.unidt.www.module.third.enterprise.service.impl;


import com.unidt.www.framework.common.pojo.PageResult;
import com.unidt.www.framework.common.util.object.BeanNullUtil;
import com.unidt.www.module.third.enterprise.dao.SystemUserEnterpriseMapper;
import com.unidt.www.module.third.enterprise.domain.SystemUserEnterpriseDO;
import com.unidt.www.module.third.enterprise.service.SystemUserEnterpriseService;
import com.unidt.www.module.third.enterprise.vo.system.SystemUserEnterpriseCreatReqVO;
import com.unidt.www.module.third.enterprise.vo.system.SystemUserEnterpriseListReqVO;
import com.unidt.www.module.third.enterprise.vo.system.SystemUserEnterpriseUpdateReqVO;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 * 部门表 服务类
 * </p>
 *
 * @author ouyangoyys
 * @since 2022-11-24
 */
@Service
@Log4j2
public class SystemUserEnterpriseServiceImpl implements SystemUserEnterpriseService {


    @Resource
    private SystemUserEnterpriseMapper systemUserEnterpriseMapper;

    @Override
    public Long create(SystemUserEnterpriseCreatReqVO reqVO) {

        SystemUserEnterpriseDO mSystemUserEnterpriseDO=new SystemUserEnterpriseDO();
        BeanUtils.copyProperties(reqVO,mSystemUserEnterpriseDO);
        systemUserEnterpriseMapper.insert(mSystemUserEnterpriseDO);

        return mSystemUserEnterpriseDO.getId();
    }

    @Override
    public void update(SystemUserEnterpriseUpdateReqVO reqVO) {

        SystemUserEnterpriseDO mSystemUserEnterpriseDO =systemUserEnterpriseMapper.selectById(reqVO.getId());
        if(mSystemUserEnterpriseDO!=null){
            BeanUtils.copyProperties(reqVO, mSystemUserEnterpriseDO, BeanNullUtil.getNullPropertyNames(reqVO));
            systemUserEnterpriseMapper.updateById(mSystemUserEnterpriseDO);
        }

    }

    @Override
    public void delete(Long id) {
        systemUserEnterpriseMapper.deleteById(id);

    }

    @Override
    public SystemUserEnterpriseDO selectByUserId(Long userId) {

        List<SystemUserEnterpriseDO> mlist=systemUserEnterpriseMapper.selectByUserId(userId);
       if(mlist.size()>0) {
           return mlist.get(0);
       }
        return null;
    }


    @Override
    public PageResult<SystemUserEnterpriseDO> list(SystemUserEnterpriseListReqVO reqVO) {
        return null;
    }
}
